package cn.wolfcode.exception;

import cn.wolfcode.domain.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.sql.SQLIntegrityConstraintViolationException;
//全局异常处理
@RestControllerAdvice
public class GlobalExceptionHandler {
    //处理数据重复添加的异常
    @ExceptionHandler(SQLIntegrityConstraintViolationException.class)
    public Result handle(SQLIntegrityConstraintViolationException e){
        return Result.error("失恋的小狗密码错误");
    }
    //处理没有登录的异常
    @ExceptionHandler(NoLoginException.class)
    public Result handle(NoLoginException e){
        return Result.error(e.getMessage());
    }


}
